package cn.marinda.resturants.mapper;

import cn.marinda.resturants.entity.Meal;
import cn.marinda.resturants.global.Pages;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.context.annotation.Primary;

import java.math.BigDecimal;
import java.util.List;

/** 菜品mapper
 * @date 2021/11/16
 * @author Marinda
 *
 */
public interface MealMapper extends BaseMapper<Meal> {

    /**
     * 选择由uid
     *
     * @param uid uid
     * @return {@link Meal}
     */
    @Select("select * from r_meal where uid = #{uid}")
    Meal selectByUid(String uid);


    /**
     * 选择喜欢的名字
     *
     * @param name 的名字
     * @return {@link List}<{@link Meal}>
     */
    @Select("select * from r_meal where name like concat('%',#{name},'%')")
    List<Meal> selectLikeByName(String name);

    /** 查询指定类型的的列表数据
     *
     * @param type 类型
     * @return 列表结果
     */
    @Select("select * from r_meal where type = #{type}")
    List<Meal> selectTypeQueryList(String type);

    @Insert("insert into r_meal(uid,name,day_number,type,price,logo,description) VALUES(#{uid},#{name},#{dayNumber},#{type},#{price},#{logo},#{description})")
    int addMeal(Meal meal);

    /** 查询指定价格范围内的餐品列表
     *
     * @param startPrice 起始价
     * @param endPrice 结束价
     * @return 列表结果
     */
    @Select("select * from r_meal where price between #{startPrice} and #{endPrice}")
    List<Meal> selectPriceJoint(BigDecimal startPrice, BigDecimal endPrice);

    /** 查询
     *
     * @param uid
     * @return
     */
    @Select("select day_number from r_meal where uid= #{uid}")
    int selectDayNumber(String uid);

    /**
     * 删除由uid
     *
     * @param uid uid
     * @return boolean
     */
    @Delete("delete from r_meal where uid=#{uid}")
    boolean deleteByUid(String uid);


    /**
     * 选择页面 定义一个meal的分页
     *
     * @param pages 页面
     * @return {@link IPage}<{@link Meal}>
     * @data 2021/12/13
     */

    @Select("select * from r_meal")
    IPage<Meal> selectPages(Pages<?> pages);
}
